home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: delta / whiteline CD Series - delta.iso / systems / unixtkit / man.arc / SH.MAN < prev    next >
Text File  |  1988-03-28  |  14KB  |  463 lines

  1.  
  2.  
  3.  
  4.         SH                    ST-UNIX User's Manual                    SH
  5.  
  6.  
  7.  
  8.         COMMAND
  9.              sh - comamnd line interpreter
  10.  
  11.         FORMAT
  12.              sh [ -enstuvx ] [ file ] ...
  13.  
  14.         DESCRIPTION
  15.              _✓S_✓h is a command line interpreter nterface to GEMDOS. It per-
  16.              mits  the  typing of commands from the keyboard and replaces
  17.              the GEM desktop.
  18.  
  19.              The shell provides features found in  programming  languages
  20.              such as varaibles and loops.
  21.  
  22.         OPTIONS
  23.              -e   if the shell is not in interactive mode  (ie.  commands
  24.                   are  being  read from a file) the shell exits if a com-
  25.                   mand fails.
  26.  
  27.              -n   commands are  read,  and  variable  substitution  takes
  28.                   place, but the commands are not executed.
  29.  
  30.              -t   shell exits after reading and executing one command.
  31.  
  32.              -u   treat unset variables as an error when substituting.
  33.  
  34.              -v   print input lines as they are read.
  35.  
  36.              -x   print the command line before it is executed.
  37.  
  38.              -    turn off -x and -v options
  39.  
  40.         COMMANDS
  41.              Command consist of a sequence of words. The  first  word  is
  42.              the  command  name and the tail is the arguments to the com-
  43.              mand. More than one command can be placed on a line,  a  ';'
  44.              separates the commands.
  45.  
  46.              Conditional execution of commands can be formed be  separat-
  47.              ing  the command with the operators '&&' and '||', for 'and'
  48.              and 'or' resepctively.  Logical 'and', if the  execution  of
  49.              the  first  command  is  successful the second one proceeds,
  50.              else the rest of the command line  is  terminated.   Logical
  51.              'or',  the  second command is executed only if the first one
  52.              fails.
  53.  
  54.         REPETITION AND CONDITIONAL EXECUTION OF COMMANDS
  55.              A number of inbuilt commands  are  provided  for  performing
  56.              loops and conditional execution.  Loops
  57.  
  58.              Three types of loop control are provided.
  59.  
  60.  
  61.  
  62.  
  63.         Printed 10/April/1987    1st April 1987                         1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.         SH                    ST-UNIX User's Manual                    SH
  71.  
  72.  
  73.  
  74.              for name [in word ...] do command-list done
  75.  
  76.                   For every iteration of the loop, name is setto the next
  77.                   word  in  the  word list.  If the 'in' command and word
  78.                   list are ommited the variable '$@' (see later) is used.
  79.                   Execution  of the command list terminates when ther are
  80.                   no more words in the list.
  81.  
  82.                   This example displays the names of all files  with  the
  83.                   extension '.c':
  84.  
  85.  
  86.                        for i in *.c
  87.                        do
  88.  
  89.                             echo File: $i
  90.  
  91.                        done
  92.  
  93.              while command-list1 [ do command-list2 ] done
  94.  
  95.                   The while command executes  command-list1  and  if  the
  96.                   last  command in the list returns true command-list2 is
  97.                   executed.  Execution  continues   until   command-list1
  98.                   fails.
  99.  
  100.                   The following example asks the user for  a  name  of  a
  101.                   file to edit and then invokes the editor. When the edit
  102.                   is complete the user is asked for  another  file  name.
  103.                   This continues indefinitly.
  104.  
  105.  
  106.                        while true
  107.                        do
  108.  
  109.                             echo -n File to edit
  110.                             read filename
  111.                             edit $filename
  112.  
  113.                        done
  114.  
  115.              if command-list1 then list1 [ elif command-list2 then  list2
  116.              ] ... [ else list ] fi
  117.  
  118.                   If executes command-list1, if the last command  in  the
  119.                   list  returns  true then list1 is executed. If the com-
  120.                   mand fails control passes to elif, then, or if returns.
  121.  
  122.                   The example shows the printing of  a  filename  is  the
  123.                   file exists.
  124.  
  125.  
  126.  
  127.  
  128.  
  129.         Printed 10/April/1987    1st April 1987                         2
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.         SH                    ST-UNIX User's Manual                    SH
  137.  
  138.  
  139.  
  140.                        echo -n File /?
  141.                        read filename
  142.                        if test -f $filename
  143.                        then
  144.  
  145.                             echo $filename
  146.  
  147.                        done
  148.  
  149.              case word in [ pattern ) command-list ;; ] ... esac
  150.  
  151.                   The case command executes the  command-list  associated
  152.                   withthe matching of word with pattern
  153.  
  154.                   The example shows how to change the name of a file.
  155.  
  156.  
  157.                        echo -n File /?
  158.                        read filename
  159.                        case $filename in
  160.  
  161.                             a.c) filename=b.c;;
  162.                             c.c) filename=b.c;;
  163.  
  164.                        esac
  165.  
  166.         VARIABLES
  167.              The shell provides variables as in  conventional  languages.
  168.              Variables  are  assigned  a value with the '=' operator. The
  169.              varaible name is composed of a sequence of letters,  digits,
  170.              or characters * @ # ? $ !.
  171.  
  172.  
  173.              var-name=string
  174.  
  175.  
  176.  
  177.              Variable substitution on the command line is performed using
  178.              the '$' operator.
  179.  
  180.  
  181.                   $variable=a long string
  182.                   $echo ${variable}
  183.                   a long string
  184.                   $
  185.  
  186.  
  187.  
  188.              The '{' and '}' braces in the example may be ommited if spe-
  189.              cial  characters are not contained in the variable name. The
  190.              special characters are discussed.
  191.  
  192.  
  193.  
  194.  
  195.         Printed 10/April/1987    1st April 1987                         3
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.         SH                    ST-UNIX User's Manual                    SH
  203.  
  204.  
  205.  
  206.                   ${varname-word}  If  the  variable  is  set  (has  been
  207.                   assigned  a  value) it's value is substituted, else the
  208.                   word is substituted.
  209.  
  210.                   ${varname=word} If the variable is not set, it  is  set
  211.                   to word, and it's value substituted.
  212.  
  213.                   ${varname?word} If the variable is not set the word  is
  214.                   printed and the shell exits.
  215.  
  216.                   ${varname+word} If the variable is set, word is substi-
  217.                   tuted, otherwise nothing is substituted.
  218.  
  219.              There are a number of  internal  parameters  to  the  shell.
  220.              These can not be changed by assignment.
  221.  
  222.                   number The shell argument corresponding to number.  For
  223.                   example $0 is the command name 'sh'.
  224.  
  225.                   # The number of parameters to the shell.
  226.  
  227.                   - The options supplied to the shell.
  228.  
  229.                   ?  The value of the error returned by the last  command
  230.                   executed.
  231.  
  232.              The shell has defined some variables which are accessable to
  233.              the user.
  234.  
  235.                   HOME The default directory used by 'cd' when  no  argu-
  236.                   ment is supplied.
  237.  
  238.                   PATH The search path used in lokating a command  to  be
  239.                   executed.
  240.  
  241.                   PS1 PS2 The prompt string, PS2 is used when a  partialy
  242.                   completed command is typed.
  243.  
  244.         QUOTING OF STRINGS ON THE COMMAND
  245.              The interpretation of characters in the command line can  be
  246.              changed  by the use of quotes. The quotes ' and " are passed
  247.              unaltered to the command  for  it's  interpretation.  The  '
  248.              quote  passes  everything  unaltered, but the " quote inter-
  249.              prets $ as variable expansion. be not interpreted.  This  is
  250.              useful  for inserting special characters, syuch as '$', into
  251.              the command line, and continueing very long  lines  (as  the
  252.              newline character is ignored). A string in the backquotes ``
  253.              is executed as a command and  the  output  of  that  command
  254.              inserted into the command line. For example:
  255.  
  256.                   pathname=`pwd`
  257.  
  258.  
  259.  
  260.  
  261.         Printed 10/April/1987    1st April 1987                         4
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.         SH                    ST-UNIX User's Manual                    SH
  269.  
  270.  
  271.  
  272.              set the variable 'pathname' to the current directory.
  273.  
  274.         INPUT-OUTPUT REDIRECTION
  275.              The input and output of a command can  be  redirected  using
  276.              the operators
  277.  
  278.                   <filename makes the command take it's  input  from  the
  279.                   file 'filename'.
  280.  
  281.                   >filename will cause the command to send its output  to
  282.                   the file 'filename' rather than a file.
  283.  
  284.                   command1 | command2 pipelines of commands can be formed
  285.                   using  the '|' operator. A pipline allows the output of
  286.                   one command to form the input of another. For  example,
  287.                   command1  will  send  it's output to form the input for
  288.                   command2.
  289.  
  290.         COMMAND EXECTION
  291.              When the command line has be processed  (variable  substitu-
  292.              tion has taken place) then command is executed. The variable
  293.              PATH is used in locating the position of the command on  the
  294.              disc.  The  pathnames  in the variable list are searched for
  295.              the command, and if it is found the command is executed. The
  296.              separator ':' is used to separate pathnames in the list.
  297.  
  298.              Before the command is executed it's type is checked. If  the
  299.              file  is  a binary then the command, arguments, and environ-
  300.              ment are passed to GEMDOS for  execution.  If  the  file  is
  301.              text, the shell takes the lines as input and executes them.
  302.  
  303.              The environment is made up of the  'exported'  variables  in
  304.              the  shell. The format of the environment passed to the com-
  305.              mand is a list of null  terminated  strings  which  is  ter-
  306.              minated by a null.
  307.  
  308.         COMMAND HISTORY AND COMMAND LINE EDITING
  309.              The history mechanism allows previously typed commands to be
  310.              used  without  having to retype the whole line again. If the
  311.              UP-ARROW key is pressed once the previous  command  type  is
  312.              displayed.  The  key  may  be pressed upto the first command
  313.              typed. Pressing the DOWN-ARROW key  lets  you  step  forward
  314.              from the current command typed.
  315.  
  316.              Command lines may be edited using the left and  right  arrow
  317.              keys.  Moving  the  cursor over a previously typed character
  318.              allows text to be inserted before the cursor.
  319.  
  320.              There are a number of editing keys available:
  321.  
  322.                   ^I - TAB inserts spaces upto the next tab  position  in
  323.                   the line. Tabs are placed at every eight characters.
  324.  
  325.  
  326.  
  327.         Printed 10/April/1987    1st April 1987                         5
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.         SH                    ST-UNIX User's Manual                    SH
  335.  
  336.  
  337.  
  338.                   ^U deletes the whole line.
  339.  
  340.                   ^W deletes the previous word.
  341.  
  342.                   BS - backspace deletes the character before the cursor.
  343.  
  344.                   DEL deletes the character under the cursor.
  345.  
  346.         INBUILT SHELL COMMANDS
  347.              The following comamnds a special to the shell and  are  exe-
  348.              cuted internaly.
  349.  
  350.                   : This command does nothing except evaluate it's  argu-
  351.                   ments. It can be used as a comment.
  352.  
  353.                   break Will cause termination of a for or while loop.
  354.  
  355.                   clear Clears the screen.
  356.  
  357.                   continue Execution continues on the next  iteration  of
  358.                   the for or while loop.
  359.  
  360.                   cd pathname The working directory is changed  to  path-
  361.                   name.
  362.  
  363.                   eval command Command is executed
  364.  
  365.                   exec command Same as eval.
  366.  
  367.                   exit [error] The shell is terminated. Error is a number
  368.                   which  is  returned  if  defined,  default is zero. The
  369.                   shell can also  be  terminated  by  typing  ^D  to  the
  370.                   prompt.
  371.  
  372.                   export [varname ] The variable is marked  for  exporta-
  373.                   tion  to  an  executing command. If no variable is sup-
  374.                   plied a list of the exportable variables is displayed.
  375.  
  376.                   history Displays the history of command lines  for  the
  377.                   last 20 commands executed.
  378.  
  379.                   read name ...  A line is read  from  the  keyboard  and
  380.                   it's  value  assigned to the variable. If more than one
  381.                   variable is specified each word  is  assigned  to  each
  382.                   variable, with any remaining words assigned to the last
  383.                   varibale.
  384.  
  385.                   readonly  [  varname  ]  The  variable  is  marked   as
  386.                   readonly.  It's  value  cannot be changed by subsequent
  387.                   assignment. If  no  variable  is  supplied  a  list  of
  388.                   readonly variables is displayed.
  389.  
  390.  
  391.  
  392.  
  393.         Printed 10/April/1987    1st April 1987                         6
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.         SH                    ST-UNIX User's Manual                    SH
  401.  
  402.  
  403.  
  404.                   set [-entuvx] Allows the  setting  of  argument  flags.
  405.                   These  are defined at the beginning of the document. If
  406.                   no argument is supplied the values of the variables are
  407.                   displayed.
  408.  
  409.                   shift The shell  arguments  are  renamed.  For  example
  410.                   argument $2 becomes $1
  411.  
  412.                   times  command  The  execution  time  for  command   is
  413.                   displayed.
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.         Printed 10/April/1987    1st April 1987                         7
  460.  
  461.  
  462.  
  463.